#include "share.hpp"

void reader(int Server_fd)
{
    char str[1024] = {0};

    while(1)
    {
        ssize_t return_read_value = read(Server_fd, str, sizeof(str));
        //返回读到的字节数
        if(return_read_value == 0)
        {
            cout << "return_read_val == 0, reader complete" << endl;
            break;
        }
        else if(return_read_value > 0)
        {
            cout << "Client commend: " << str << endl;
        }
        else
        {
            cout << "read error:" << errno << " reason :" << strerror(errno) << endl;
            break;
        }
    }
    
    //关闭服务器读端
    close(Server_fd);
}

int main()
{

    Fifo fifo;
    fifo.CreateNamePipe();

    int Server_fd = open(Path, O_RDONLY);
    if(Server_fd < 0)
    {
        cout << "Server open error:" << errno << " reason :" << strerror(errno) << endl;
        exit(2);
    } 

    cout << "Server open success" << endl;
    reader(Server_fd);
    
    return 0;
}